From e4baac0ac2f340c0637b0cc0f857f9e57fef0642 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 17 Feb 2016 01:14:49 +0000 Subject: [PATCH] Recompile when RUSTFLAGS changes --- src/cargo/ops/cargo_rustc/fingerprint.rs | 14 ++++++- tests/test_cargo_compile.rs | 50 ++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/src/cargo/ops/cargo_rustc/fingerprint.rs b/src/cargo/ops/cargo_rustc/fingerprint.rs index 837b14bc1..8195ee378 100644 --- a/src/cargo/ops/cargo_rustc/fingerprint.rs +++ b/src/cargo/ops/cargo_rustc/fingerprint.rs @@ -111,6 +111,7 @@ pub struct Fingerprint { deps: Vec<(String, Arc)>, local: LocalFingerprint, memoized_hash: Mutex>, + rustflags: Vec, } #[derive(RustcEncodable, RustcDecodable, Hash)] @@ -160,6 +161,9 @@ impl Fingerprint { if self.profile != old.profile { bail!("profile configuration has changed") } + if self.rustflags != old.rustflags { + return Err(internal("RUSTFLAGS has changed")) + } match (&self.local, &old.local) { (&LocalFingerprint::Precalculated(ref a), &LocalFingerprint::Precalculated(ref b)) => { @@ -202,8 +206,9 @@ impl hash::Hash for Fingerprint { ref deps, ref local, memoized_hash: _, + ref rustflags, } = *self; - (rustc, features, target, profile, deps, local).hash(h) + (rustc, features, target, profile, deps, local, rustflags).hash(h) } } @@ -222,6 +227,7 @@ impl Encodable for Fingerprint { (a, b.hash()) }).collect::>().encode(e) })); + try!(e.emit_struct_field("rustflags", 6, |e| self.rustflags.encode(e))); Ok(()) }) } @@ -252,9 +258,11 @@ impl Decodable for Fingerprint { features: String::new(), deps: Vec::new(), memoized_hash: Mutex::new(Some(hash)), + rustflags: Vec::new(), })) }).collect() - } + }, + rustflags: try!(d.read_struct_field("rustflags", 6, decode)), }) }) } @@ -346,6 +354,7 @@ fn calculate<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) deps: deps, local: local, memoized_hash: Mutex::new(None), + rustflags: cx.rustflags_args(unit), }); cx.fingerprints.insert(*unit, fingerprint.clone()); Ok(fingerprint) @@ -425,6 +434,7 @@ pub fn prepare_build_cmd<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) deps: Vec::new(), local: local, memoized_hash: Mutex::new(None), + rustflags: Vec::new(), }; let compare = compare_old_fingerprint(&loc, &fingerprint); log_compare(unit, &compare); diff --git a/tests/test_cargo_compile.rs b/tests/test_cargo_compile.rs index d51c51d78..9530e9417 100644 --- a/tests/test_cargo_compile.rs +++ b/tests/test_cargo_compile.rs @@ -2396,3 +2396,53 @@ test!(rustflags_plugin_dep_with_target { .arg("--target").arg(host), execs().with_status(0)); }); + +test!(rustflags_recompile { + let p = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.1" + "#) + .file("src/lib.rs", ""); + p.build(); + + assert_that(p.cargo("build"), + execs().with_status(0)); + // Setting RUSTFLAGS forces a recompile + assert_that(p.cargo("build").env("RUSTFLAGS", "-Z bogus"), + execs().with_status(101)); +}); + +test!(rustflags_recompile2 { + let p = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.1" + "#) + .file("src/lib.rs", ""); + p.build(); + + assert_that(p.cargo("build").env("RUSTFLAGS", "--cfg foo"), + execs().with_status(0)); + // Setting RUSTFLAGS forces a recompile + assert_that(p.cargo("build").env("RUSTFLAGS", "-Z bogus"), + execs().with_status(101)); +}); + +test!(rustflags_no_recompile { + let p = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.1" + "#) + .file("src/lib.rs", ""); + p.build(); + + assert_that(p.cargo("build").env("RUSTFLAGS", "--cfg foo"), + execs().with_status(0)); + assert_that(p.cargo("build").env("RUSTFLAGS", "--cfg foo"), + execs().with_stdout("").with_status(0)); +}); -- 2.30.2